/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package View;

import javax.swing.JOptionPane;
import javax.swing.JTextField;

/**
 *
 * @author Sobrenombre
 */
public class Validations {


  public static boolean vacio(JTextField txt, String error){
    if (txt.getText().trim().compareTo("")==0){
      JOptionPane.showMessageDialog(null,error,"Error",JOptionPane.ERROR_MESSAGE);
      txt.requestFocusInWindow();
      return false;
    }
    return true;
  }
   public static boolean numericoEntero(JTextField txt, String error) {
    if (txt.getText().trim().compareTo("")==0)
      return true;
    try {
      int n = Integer.parseInt(txt.getText());
    }
    catch (Exception e) {
      JOptionPane.showMessageDialog(null,error,"Error",JOptionPane.ERROR_MESSAGE);
      txt.requestFocusInWindow();
      return false;
    }
    return true;
  }

    public static boolean numericoDouble(JTextField txt, String error, int signo){
    boolean banError = false;
    double n = 0;
    try{
       n = Double.parseDouble(txt.getText());
    }catch (Exception e){
      banError = true;
    }finally{
      if(!banError){
          if(signo < 0 && n > 0 || signo > 0 && n < 0) banError = true;
      }
      if(banError){
          JOptionPane.showMessageDialog(null,error,"Error",JOptionPane.ERROR_MESSAGE);
          txt.requestFocusInWindow();
          return false;
      }
      return true;
    }
  }



   public static boolean esCero(JTextField txt, String error){
       if(txt.getText().trim().compareTo("0") != 0)
           return true;
       else{
           JOptionPane.showMessageDialog(null, error,"Error",JOptionPane.ERROR_MESSAGE);
           txt.requestFocusInWindow();
           return false;
       }
   }
}
